package com.feihao.zhou.controller;

import com.feihao.zhou.domain.User;
import com.feihao.zhou.service.UserService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*restful风格：*/
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;

    @PostMapping
    public void save(User user){
        boolean save = userService.save(user);
        System.out.println(user);
    }

    @DeleteMapping("/{uuid}")
    public boolean delete(@PathVariable Integer uuid){
        boolean delete = userService.delete(uuid);
        return delete;
    }

    @PutMapping
    public boolean update(User user){
        boolean update = userService.update(user);
        return update;
    }

    @GetMapping("/{uuid}")
    public User getById(@PathVariable Integer uuid){
        User us = userService.getById(uuid);
        return us;
    }

    @GetMapping("/{page}/{size}")
    public PageInfo<User> getAll(@PathVariable int page,@PathVariable int size){
        PageInfo<User> all = userService.getAll(page, size);
        return all;
    }

    @PostMapping("/login")
    public User login(String userName,String password){
        User us = userService.getByUserNameAndPassword(userName, password);
        return us;
    }
}


/*
*  @Autowired
    private UserService userService;

    @PostMapping
    public void save(User user){
        boolean save = userService.save(user);
        System.out.println(user);
    }

    @GetMapping("/{uuid}")
    public boolean delete(@PathVariable Integer uuid){
        boolean delete = userService.delete(uuid);
        return delete;
    }

    @PutMapping
    public boolean update(User user){
        boolean update = userService.update(user);
        return update;
    }

    @GetMapping("/{uuid}")
    public User getById(@PathVariable Integer uuid){
        User us = userService.getById(uuid);
        return us;
    }

    @GetMapping("/{page}/{size}")
    public PageInfo<User> getAll(@PathVariable int page,@PathVariable int size){
        PageInfo<User> all = userService.getAll(page, size);
        return all;
    }

    @PostMapping("/login")
    public User login(String userName,String password){
        User us = userService.getByUserNameAndPassword(userName, password);
        return us;
    }*/